package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.service.SearchQuestionsService;

import net.sf.json.JSONArray;


@Controller
@Scope(value="prototype")
public class SearchQuestionsAction extends ActionSupport implements ServletResponseAware,SessionAware,ServletRequestAware{
	 
	private HttpServletResponse resp;
	 private  Map<String,Object> session; 
	 private HttpServletRequest req;	
	
	 @Override
	public void setServletRequest(HttpServletRequest request) {
		this.req=request;
		
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session=session;
		
	}

	@Override
	public void setServletResponse(HttpServletResponse response) {
        this.resp = response;		
	}
	
	@Resource
	private SearchQuestionsService searchQestionsService;
	
	public void searchQuestions(){
		    resp.setCharacterEncoding("utf8");
		    JSONArray js = new JSONArray();
		 	js = searchQestionsService.findAllQuestions();
		 	try {
				PrintWriter pw = resp.getWriter();
				pw.write(js.toString());
				pw.flush();
				pw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 	
		
		
	}
	
	

}
